<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="告警标题" prop="alarmTitle">
        <el-input
          v-model="queryParams.alarmTitle"
          placeholder="请输入告警标题"
          clearable
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="告警级别" prop="alarmLevel">
        <el-select
          v-model="queryParams.alarmLevel"
          placeholder="请选择级别"
          clearable
          style="width: 120px"
        >
          <el-option label="信息" value="info" />
          <el-option label="警告" value="warning" />
          <el-option label="严重" value="critical" />
          <el-option label="紧急" value="emergency" />
        </el-select>
      </el-form-item>
      <el-form-item label="告警状态" prop="alarmStatus">
        <el-select
          v-model="queryParams.alarmStatus"
          placeholder="请选择状态"
          clearable
          style="width: 120px"
        >
          <el-option label="未处理" value="unhandled" />
          <el-option label="处理中" value="handling" />
          <el-option label="已处理" value="handled" />
          <el-option label="已忽略" value="ignored" />
        </el-select>
      </el-form-item>
      <el-form-item label="告警源" prop="alarmSource">
        <el-select
          v-model="queryParams.alarmSource"
          placeholder="请选择告警源"
          clearable
          filterable
          style="width: 160px"
        >
          <el-option
            v-for="item in alarmSourceOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="处理人" prop="handlePerson">
        <el-input
          v-model="queryParams.handlePerson"
          placeholder="请输入处理人"
          clearable
          style="width: 140px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="告警时间" prop="alarmTimeRange">
        <el-date-picker
          v-model="queryParams.alarmTimeRange"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          style="width: 360px"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:alarmRecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:alarmRecord:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:alarmRecord:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:alarmRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table 
      v-loading="loading" 
      :data="alarmRecordList" 
      @selection-change="handleSelectionChange"
      stripe
      border
      highlight-current-row
      class="common-table"
    >
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="ID" align="center" prop="alarmId" width="80" />
      <el-table-column label="告警信息" align="left" min-width="200">
        <template slot-scope="scope">
          <div>
            <div style="font-weight: 500; margin-bottom: 4px; display: flex; align-items: center;">
              <el-tag :type="getLevelTagType(scope.row.alarmLevel)" size="mini" style="margin-right: 8px;">
                {{ getLevelLabel(scope.row.alarmLevel) }}
              </el-tag>
              <span>{{ scope.row.alarmTitle }}</span>
            </div>
            <div style="font-size: 12px; color: #909399;">
              {{ getShortText(scope.row.alarmMessage, 80) }}
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="告警源" align="center" width="140">
        <template slot-scope="scope">
          <div>
            <div style="font-weight: 500; color: #409EFF;">{{ scope.row.alarmSource }}</div>
            <div style="font-size: 12px; color: #909399;" v-if="scope.row.deviceId">
              设备ID: {{ scope.row.deviceId }}
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="触发信息" align="center" width="120">
        <template slot-scope="scope">
          <div v-if="scope.row.triggerValue && scope.row.thresholdValue">
            <div style="font-size: 12px; color: #909399;">触发值</div>
            <div style="font-weight: 500; color: #F56C6C;">{{ scope.row.triggerValue }}</div>
            <div style="font-size: 12px; color: #909399;">阈值: {{ scope.row.thresholdValue }}</div>
          </div>
          <div v-else style="color: #909399;">-</div>
        </template>
      </el-table-column>
      <el-table-column label="状态信息" align="center" width="120">
        <template slot-scope="scope">
          <div>
            <el-tag :type="getStatusTagType(scope.row.alarmStatus)" size="mini" style="margin-bottom: 4px;">
              {{ getStatusLabel(scope.row.alarmStatus) }}
            </el-tag>
            <div style="font-size: 12px; color: #909399;" v-if="scope.row.alarmCount > 1">
              重复{{ scope.row.alarmCount }}次
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="告警时间" align="center" width="140">
        <template slot-scope="scope">
          <div>
            <div style="font-size: 12px; color: #909399;">首次</div>
            <div style="font-size: 12px; margin-bottom: 4px;">{{ parseTime(scope.row.firstAlarmTime, '{y}-{m}-{d} {h}:{i}') }}</div>
            <div style="font-size: 12px; color: #909399;" v-if="scope.row.lastAlarmTime !== scope.row.firstAlarmTime">
              最近: {{ parseTime(scope.row.lastAlarmTime, '{m}-{d} {h}:{i}') }}
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="处理信息" align="center" width="140">
        <template slot-scope="scope">
          <div v-if="scope.row.handlePerson">
            <div style="font-weight: 500; color: #67C23A;">{{ scope.row.handlePerson }}</div>
            <div style="font-size: 12px; color: #909399;" v-if="scope.row.handleTime">
              {{ parseTime(scope.row.handleTime, '{m}-{d} {h}:{i}') }}
            </div>
            <div style="font-size: 12px; color: #67C23A;" v-if="scope.row.handleResult">
              {{ getShortText(scope.row.handleResult, 30) }}
            </div>
          </div>
          <div v-else style="color: #909399;">未处理</div>
        </template>
      </el-table-column>
      <el-table-column label="关闭信息" align="center" width="100">
        <template slot-scope="scope">
          <div v-if="scope.row.closeTime">
            <div style="font-size: 12px;">{{ parseTime(scope.row.closeTime, '{m}-{d} {h}:{i}') }}</div>
            <el-tag :type="scope.row.autoClose === '1' ? 'success' : 'info'" size="mini">
              {{ scope.row.autoClose === '1' ? '自动' : '手动' }}
            </el-tag>
          </div>
          <div v-else style="color: #909399;">未关闭</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:alarmRecord:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:alarmRecord:remove']"
            style="color: #F56C6C"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改告警记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-tabs v-model="activeTab" type="border-card">
          <el-tab-pane label="基本信息" name="basic">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="告警规则" prop="ruleId">
                  <el-select v-model="form.ruleId" placeholder="请选择告警规则" filterable style="width: 100%">
                    <el-option
                      v-for="item in ruleOptions"
                      :key="item.ruleId"
                      :label="`${item.ruleName} (ID:${item.ruleId})`"
                      :value="item.ruleId"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="告警级别" prop="alarmLevel">
                  <el-select v-model="form.alarmLevel" placeholder="请选择告警级别" style="width: 100%">
                    <el-option label="信息" value="info">
                      <span style="color: #909399">信息 - 一般性提示信息</span>
                    </el-option>
                    <el-option label="警告" value="warning">
                      <span style="color: #E6A23C">警告 - 需要关注的异常</span>
                    </el-option>
                    <el-option label="严重" value="critical">
                      <span style="color: #F56C6C">严重 - 影响业务的故障</span>
                    </el-option>
                    <el-option label="紧急" value="emergency">
                      <span style="color: #FF0000">紧急 - 需立即处理</span>
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="告警标题" prop="alarmTitle">
                  <el-input 
                    v-model="form.alarmTitle" 
                    placeholder="请输入告警标题"
                    maxlength="200"
                    show-word-limit
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="告警源" prop="alarmSource">
                  <el-select v-model="form.alarmSource" placeholder="请选择告警源" filterable style="width: 100%">
                    <el-option
                      v-for="item in alarmSourceOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="相关设备" prop="deviceId">
                  <el-select v-model="form.deviceId" placeholder="请选择设备" filterable style="width: 100%">
                    <el-option
                      v-for="item in deviceOptions"
                      :key="item.deviceId"
                      :label="`${item.deviceCode} - ${item.deviceName}`"
                      :value="item.deviceId"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="告警消息" prop="alarmMessage">
                  <el-input 
                    v-model="form.alarmMessage" 
                    type="textarea" 
                    placeholder="请输入详细的告警消息内容"
                    :rows="4"
                    maxlength="1000"
                    show-word-limit
                  />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="触发详情" name="trigger">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="触发值" prop="triggerValue">
                  <el-input v-model="form.triggerValue" placeholder="请输入触发值" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="阈值" prop="thresholdValue">
                  <el-input v-model="form.thresholdValue" placeholder="请输入阈值" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="告警状态" prop="alarmStatus">
                  <el-select v-model="form.alarmStatus" placeholder="请选择状态" style="width: 100%">
                    <el-option label="未处理" value="unhandled">
                      <span style="color: #F56C6C">未处理 - 等待处理</span>
                    </el-option>
                    <el-option label="处理中" value="handling">
                      <span style="color: #E6A23C">处理中 - 正在处理</span>
                    </el-option>
                    <el-option label="已处理" value="handled">
                      <span style="color: #67C23A">已处理 - 处理完成</span>
                    </el-option>
                    <el-option label="已忽略" value="ignored">
                      <span style="color: #909399">已忽略 - 忽略处理</span>
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="重复次数">
                  <el-input-number
                    v-model="form.alarmCount"
                    :min="1"
                    :max="999"
                    placeholder="重复告警次数"
                    style="width: 100%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="首次告警" prop="firstAlarmTime">
                  <el-date-picker 
                    v-model="form.firstAlarmTime"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="请选择首次告警时间"
                    style="width: 100%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="最后告警" prop="lastAlarmTime">
                  <el-date-picker 
                    v-model="form.lastAlarmTime"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="请选择最后告警时间"
                    style="width: 100%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-alert
                  title="触发说明"
                  type="info"
                  description="触发值：实际监测到的数值；阈值：告警规则设定的临界值。当触发值超出阈值范围时产生告警。"
                  :closable="false"
                  show-icon>
                </el-alert>
              </el-col>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="处理信息" name="handle">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="处理人" prop="handlePerson">
                  <el-input v-model="form.handlePerson" placeholder="请输入处理人" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="处理时间" prop="handleTime">
                  <el-date-picker 
                    v-model="form.handleTime"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="请选择处理时间"
                    style="width: 100%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="处理结果">
                  <el-input 
                    v-model="form.handleResult" 
                    type="textarea" 
                    placeholder="请输入处理结果和解决方案"
                    :rows="4"
                    maxlength="500"
                    show-word-limit
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="关闭时间" prop="closeTime">
                  <el-date-picker 
                    v-model="form.closeTime"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="请选择关闭时间"
                    style="width: 100%"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="自动关闭">
                  <el-switch
                    v-model="form.autoClose"
                    active-value="1"
                    inactive-value="0"
                    active-text="自动关闭"
                    inactive-text="手动关闭"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-alert
                  title="处理说明"
                  type="warning"
                  description="请详细记录处理过程和结果，便于后续分析和改进。自动关闭的告警会在条件恢复正常后自动关闭。"
                  :closable="false"
                  show-icon>
                </el-alert>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAlarmRecord, getAlarmRecord, delAlarmRecord, addAlarmRecord, updateAlarmRecord } from "@/api/system/alarmRecord";

export default {
  name: "AlarmRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 告警记录表格数据
      alarmRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 当前活跃标签
      activeTab: "basic",
      // 告警源选项
      alarmSourceOptions: [],
      // 规则选项
      ruleOptions: [],
      // 设备选项
      deviceOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        alarmTitle: null,
        alarmLevel: null,
        alarmStatus: null,
        alarmSource: null,
        handlePerson: null,
        alarmTimeRange: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ruleId: [
          { required: true, message: "告警规则不能为空", trigger: "change" }
        ],
        alarmTitle: [
          { required: true, message: "告警标题不能为空", trigger: "blur" }
        ],
        alarmMessage: [
          { required: true, message: "告警消息不能为空", trigger: "blur" }
        ],
        alarmLevel: [
          { required: true, message: "告警级别不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getAlarmSourceOptions();
    this.getRuleOptions();
    this.getDeviceOptions();
  },
  methods: {
    /** 查询告警记录列表 */
    getList() {
      this.loading = true;
      // 处理日期范围查询
      if (this.queryParams.alarmTimeRange && this.queryParams.alarmTimeRange.length === 2) {
        this.queryParams.firstAlarmTimeStart = this.queryParams.alarmTimeRange[0];
        this.queryParams.firstAlarmTimeEnd = this.queryParams.alarmTimeRange[1];
      } else {
        this.queryParams.firstAlarmTimeStart = null;
        this.queryParams.firstAlarmTimeEnd = null;
      }
      
      listAlarmRecord(this.queryParams).then(response => {
        this.alarmRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 获取告警源选项 */
    getAlarmSourceOptions() {
      // 这里应该调用API，暂时使用mock数据
      this.alarmSourceOptions = [
        { value: 'SENSOR-001', label: '水质传感器-001' },
        { value: 'SENSOR-002', label: 'pH传感器-002' },
        { value: 'SENSOR-003', label: '溶氧传感器-003' },
        { value: 'CAMERA-001', label: '监控摄像头-001' },
        { value: 'CAMERA-002', label: '监控摄像头-002' },
        { value: 'SYSTEM-MONITOR', label: '系统监控' },
        { value: 'AI-MODEL', label: 'AI检测模型' },
        { value: 'NETWORK-DEVICE', label: '网络设备' }
      ];
    },
    /** 获取规则选项 */
    getRuleOptions() {
      // 这里应该调用告警规则API，暂时使用mock数据
      this.ruleOptions = [
        { ruleId: 1001, ruleName: '水温异常检测' },
        { ruleId: 1002, ruleName: 'pH值监控' },
        { ruleId: 1003, ruleName: '溶氧量监控' },
        { ruleId: 1004, ruleName: '设备离线检测' },
        { ruleId: 1005, ruleName: '视频质量检测' },
        { ruleId: 1006, ruleName: '系统资源监控' },
        { ruleId: 1007, ruleName: 'AI模型性能监控' },
        { ruleId: 1008, ruleName: '网络连接监控' }
      ];
    },
    /** 获取设备选项 */
    getDeviceOptions() {
      // 这里应该调用设备API，暂时使用mock数据
      this.deviceOptions = [
        { deviceId: 10001, deviceCode: 'DEV-001', deviceName: '1号水质监测设备' },
        { deviceId: 10002, deviceCode: 'DEV-002', deviceName: '2号溶氧监测设备' },
        { deviceId: 10003, deviceCode: 'DEV-003', deviceName: '3号pH监测设备' },
        { deviceId: 10004, deviceCode: 'CAM-001', deviceName: '1号监控摄像头' },
        { deviceId: 10005, deviceCode: 'CAM-002', deviceName: '2号监控摄像头' },
        { deviceId: 10006, deviceCode: 'SRV-001', deviceName: '主服务器' },
        { deviceId: 10007, deviceCode: 'NET-001', deviceName: '网络交换机' },
        { deviceId: 10008, deviceCode: 'AI-001', deviceName: 'AI计算节点' }
      ];
    },
    /** 获取告警级别标签 */
    getLevelLabel(level) {
      const levelMap = {
        'info': '信息',
        'warning': '警告',
        'critical': '严重',
        'emergency': '紧急'
      };
      return levelMap[level] || level;
    },
    /** 获取告警级别标签类型 */
    getLevelTagType(level) {
      const levelMap = {
        'info': 'info',
        'warning': 'warning',
        'critical': 'danger',
        'emergency': 'danger'
      };
      return levelMap[level] || '';
    },
    /** 获取告警状态标签 */
    getStatusLabel(status) {
      const statusMap = {
        'unhandled': '未处理',
        'handling': '处理中',
        'handled': '已处理',
        'ignored': '已忽略'
      };
      return statusMap[status] || status;
    },
    /** 获取告警状态标签类型 */
    getStatusTagType(status) {
      const statusMap = {
        'unhandled': 'danger',
        'handling': 'warning',
        'handled': 'success',
        'ignored': 'info'
      };
      return statusMap[status] || '';
    },
    /** 获取截取文本 */
    getShortText(text, length = 50) {
      if (!text) return '';
      return text.length > length ? text.substring(0, length) + '...' : text;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        alarmId: null,
        ruleId: null,
        alarmTitle: null,
        alarmMessage: null,
        alarmLevel: null,
        alarmSource: null,
        deviceId: null,
        triggerValue: null,
        thresholdValue: null,
        alarmStatus: 'unhandled',
        alarmCount: 1,
        firstAlarmTime: null,
        lastAlarmTime: null,
        handlePerson: null,
        handleTime: null,
        handleResult: null,
        closeTime: null,
        autoClose: '0'
      };
      this.activeTab = "basic";
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.alarmId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加告警记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const alarmId = row.alarmId || this.ids
      getAlarmRecord(alarmId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改告警记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.alarmId != null) {
            updateAlarmRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAlarmRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const alarmIds = row.alarmId || this.ids;
      const alarmTitle = row.alarmTitle ? `"${row.alarmTitle}"` : '选中的告警记录';
      this.$modal.confirm('是否确认删除告警记录' + alarmTitle + '？').then(function() {
        return delAlarmRecord(alarmIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/alarmRecord/export', {
        ...this.queryParams
      }, `alarmRecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.common-table {
  margin-top: 10px;
}

.common-table .el-table__header th {
  background-color: #fafafa;
  color: #606266;
  font-weight: 500;
}

.el-tag {
  font-weight: 500;
}

.dialog-footer {
  text-align: right;
  padding-top: 20px;
}

.el-form .el-form-item__label {
  font-weight: 500;
  color: #606266;
}

.el-select .el-input__inner {
  cursor: pointer;
}

/* 搜索表单优化 */
.el-form--inline .el-form-item {
  margin-bottom: 10px;
}

/* 表格操作按钮间距 */
.el-table .cell .el-button + .el-button {
  margin-left: 5px;
}

/* 标签页优化 */
.el-tabs--border-card .el-tab-pane {
  padding: 20px;
}

.el-tabs--border-card .el-tabs__content {
  background-color: #fff;
}

/* 弹窗宽度响应式 */
@media (max-width: 768px) {
  .el-dialog {
    width: 95% !important;
  }
}

/* 表格列头样式优化 */
.el-table th.is-leaf {
  border-bottom: 1px solid #EBEEF5;
}

/* 告警级别标签样式优化 */
.el-tag.el-tag--info {
  color: #909399;
  background-color: #f4f4f5;
  border-color: #d3d4d6;
}

.el-tag.el-tag--warning {
  color: #E6A23C;
  background-color: #fdf6ec;
  border-color: #f5dab1;
}

.el-tag.el-tag--danger {
  color: #F56C6C;
  background-color: #fef0f0;
  border-color: #fbc4c4;
}

.el-tag.el-tag--success {
  color: #67C23A;
  background-color: #f0f9ff;
  border-color: #c2e7b0;
}

/* 告警信息显示优化 */
.alarm-info {
  text-align: left;
}

.alarm-info .level-tag {
  margin-right: 8px;
}

.alarm-info .title {
  font-weight: 500;
  margin-bottom: 4px;
}

.alarm-info .message {
  font-size: 12px;
  color: #909399;
  line-height: 1.4;
}

/* 告警源显示优化 */
.alarm-source {
  text-align: center;
}

.alarm-source .source {
  font-weight: 500;
  color: #409EFF;
  margin-bottom: 2px;
}

.alarm-source .device {
  font-size: 12px;
  color: #909399;
}

/* 触发信息显示优化 */
.trigger-info {
  text-align: center;
}

.trigger-info .label {
  font-size: 12px;
  color: #909399;
}

.trigger-info .value {
  font-weight: 500;
  color: #F56C6C;
  margin: 2px 0;
}

.trigger-info .threshold {
  font-size: 12px;
  color: #909399;
}

/* 状态信息显示优化 */
.status-info {
  text-align: center;
}

.status-info .status-tag {
  margin-bottom: 4px;
}

.status-info .count {
  font-size: 12px;
  color: #909399;
}

/* 时间信息显示优化 */
.time-info {
  text-align: center;
}

.time-info .label {
  font-size: 12px;
  color: #909399;
  margin-bottom: 2px;
}

.time-info .time {
  font-size: 12px;
  margin-bottom: 4px;
}

.time-info .recent {
  font-size: 12px;
  color: #909399;
}

/* 处理信息显示优化 */
.handle-info {
  text-align: center;
}

.handle-info .person {
  font-weight: 500;
  color: #67C23A;
  margin-bottom: 2px;
}

.handle-info .time {
  font-size: 12px;
  color: #909399;
  margin-bottom: 2px;
}

.handle-info .result {
  font-size: 12px;
  color: #67C23A;
}

/* 关闭信息显示优化 */
.close-info {
  text-align: center;
}

.close-info .time {
  font-size: 12px;
  margin-bottom: 4px;
}

.close-info .auto-tag {
  font-size: 11px;
}

/* 文本域优化 */
.el-textarea .el-textarea__inner {
  resize: vertical;
}

/* 数字输入框优化 */
.el-input-number {
  width: 100%;
}

/* 提示框样式优化 */
.el-alert {
  margin-top: 10px;
}

.el-alert .el-alert__description {
  font-size: 13px;
  line-height: 1.4;
}

/* 选择框选项样式 */
.el-select-dropdown__item {
  padding: 8px 20px;
  line-height: 1.4;
}

.el-select-dropdown__item span {
  display: block;
}

/* 级别选项颜色 */
.level-option-info {
  color: #909399;
}

.level-option-warning {
  color: #E6A23C;
}

.level-option-critical {
  color: #F56C6C;
}

.level-option-emergency {
  color: #FF0000;
}

/* 状态选项颜色 */
.status-option-unhandled {
  color: #F56C6C;
}

.status-option-handling {
  color: #E6A23C;
}

.status-option-handled {
  color: #67C23A;
}

.status-option-ignored {
  color: #909399;
}

/* 卡片样式优化 */
.el-card {
  border-radius: 6px;
}

.el-card .el-card__body {
  padding: 15px;
}

/* 搜索框宽度优化 */
.search-input {
  width: 180px;
}

.search-select {
  width: 120px;
}

.search-select-wide {
  width: 160px;
}

.search-date-range {
  width: 360px;
}

/* 表格行高优化 */
.common-table .el-table__row {
  height: auto;
}

.common-table .el-table__row td {
  padding: 8px 0;
}

/* 操作按钮样式 */
.operation-btn-edit {
  color: #409EFF;
}

.operation-btn-delete {
  color: #F56C6C;
}

/* 级别标签样式 */
.level-tag-info {
  background-color: #f4f4f5;
  border-color: #d3d4d6;
  color: #909399;
}

.level-tag-warning {
  background-color: #fdf6ec;
  border-color: #f5dab1;
  color: #E6A23C;
}

.level-tag-critical {
  background-color: #fef0f0;
  border-color: #fbc4c4;
  color: #F56C6C;
}

.level-tag-emergency {
  background-color: #fef0f0;
  border-color: #fbc4c4;
  color: #FF0000;
  font-weight: 600;
}

/* 状态标签样式 */
.status-tag-unhandled {
  background-color: #fef0f0;
  border-color: #fbc4c4;
  color: #F56C6C;
}

.status-tag-handling {
  background-color: #fdf6ec;
  border-color: #f5dab1;
  color: #E6A23C;
}

.status-tag-handled {
  background-color: #f0f9ff;
  border-color: #c2e7b0;
  color: #67C23A;
}

.status-tag-ignored {
  background-color: #f4f4f5;
  border-color: #d3d4d6;
  color: #909399;
}

/* 表格内容样式 */
.table-content {
  line-height: 1.4;
}

.table-content .main-text {
  font-weight: 500;
  margin-bottom: 4px;
}

.table-content .sub-text {
  font-size: 12px;
  color: #909399;
}

.table-content .highlight-text {
  color: #409EFF;
  font-weight: 500;
}

.table-content .success-text {
  color: #67C23A;
}

.table-content .warning-text {
  color: #E6A23C;
}

.table-content .danger-text {
  color: #F56C6C;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .search-date-range {
    width: 300px;
  }
}

@media (max-width: 992px) {
  .search-input {
    width: 150px;
  }
  
  .search-select-wide {
    width: 140px;
  }
  
  .search-date-range {
    width: 280px;
  }
}

@media (max-width: 768px) {
  .el-form--inline .el-form-item {
    display: block;
    margin-bottom: 15px;
  }
  
  .search-input,
  .search-select,
  .search-select-wide,
  .search-date-range {
    width: 100%;
  }
}
</style>
